(function(){
    var $dashboard=$("#dashboard");
    var $collectHouses=$("#collectHouses");
    var $signedHouses=$("#signedHouses");
    var $soldHouses=$("#soldHouses");
    var $listingHouses=$("#listingHouses");
    var myChart = echarts.init($dashboard[0]);
    function getFinalData(data) {
       return typeof data==='object'?data.res.data:data;
    }
    $.post(window.globalHost + '/agent-sys/report/getCurrentMonthNewHouseCount.do').success(function (data) {
        data=common.transformData(data);
        $collectHouses.html(getFinalData(data));
    });
    $.post(window.globalHost + '/agent-sys/report/getTotalSignHouseCount.do').success(function (data) {
        data=common.transformData(data);
        $signedHouses.html(getFinalData(data));
    });
    $.post(window.globalHost + '/agent-sys/report/getTotalSoldHouseCount.do').success(function (data) {
        data=common.transformData(data);
        $soldHouses.html(getFinalData(data));
    });
    $.post(window.globalHost + '/agent-sys/report/getTotalListingHouseCount.do').success(function (data) {
        data=common.transformData(data);
        $listingHouses.html(getFinalData(data));
    });
    $.post(window.globalHost + '/agent-sys/report/getSignAndSaleCount.do').success(function (data) {
        var record = common.transformData(data);
        var monthList=[];
        var saleCountList=[];
        var signCountList=[];
        $.each(record,function (idx, ele) {
            monthList.push(ele.MONTH);
            saleCountList.push(ele.SALE_COUNT);
            signCountList.push(ele.SIGN_COUNT);
        });
        // 指定图表的配置项和数据
        var option = {
            title: {
                padding: [10,20],
                text: '近期签约数和售出数'
            },
            backgroundColor: '#fff',
            // tooltip: {
            //     trigger: 'item',
            //     formatter: "{a} <br/>{b} : {c} ({d}%)"
            // },
            legend: {
                orient: 'horizontal',
                right:"top",
                data: [{name:'签约数'},{name:'售出数'}]
            },
            xAxis:{
                name:"月份",
                // data:["2016-02","2016-03","2016-04","2016-05","2016-06","2016-07","2016-08","2016-09","2016-10","2016-11","2016-12","2017-01"]
                data:monthList
            },
            yAxis:{
                min:0
            },
            series: [{
                type: 'bar',
                itemStyle:{
                    normal:{
                        color: '#1ab394'
                    }
                },
                barGap: '0%',
                barCategoryGap: '30%',
                name:"签约数",
                symbolSize:20,
                label:{
                    normal:{
                        show:true,
                        formatter:"{c}",
                        position: 'top',
                        textStyle: {
                            color: '#666666',
                            fontWeight: 'bolder',
                            fontFamily: 'sans-serif',
                            fontSize: 16
                        }
                    }
                },
                // data:_.sampleSize(_.range(0,101),12)
                data:signCountList
            },{
                type: 'bar',
                name:"售出数",
                symbolSize:10,
                label:{
                    normal:{
                        show:true,
                        formatter:"{c}",
                        position: 'top',
                        textStyle: {
                            color: '#666666',
                            fontWeight: 'bolder',
                            fontFamily: 'sans-serif',
                            fontSize: 16
                        }
                    }
                },
                // data:_.sampleSize(_.range(0,101),12)
                data:saleCountList
            }]
        };

// 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    });


})();